-- cure_percent_mon
-- create by wangy
-- 技能: 怪物恢复目标生命值(目标生命百分比)


return {
    apply = function(source, target, skillId, round, para, extra)
        -- 威力
        local force = para[1];
        local targets = {};

        -- 遍历所有的怪
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            local monster = grid.monster;

            -- 是怪物且没死
            if  grid:isOpened() and monster and
                not monster:isDead() then

                -- 2. 被恢复怪物最大生命（只恢复基础的部分）
                local targetHp = math.max(monster:query("hp"), 0);
                local maxHp = monster:queryAttrib("max_hp");

                -- 3. 恢复%最大生命
                local hp = FormulaM.invoke("CALC_BIG_DIVISION", force, maxHp, 1000);

                -- 不超过上限
                hp = math.min((maxHp - targetHp), hp);
                if hp > 0 then
                    CombatM.receiveCure(source, monster, hp);
                    table.insert(targets, monster);
                end
            end
        end

        -- 作用目标
        return targets;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

